/*	
 *				
 *					ISNW ---- It is a war.It is not warcraft!
 *
 *
 *					Author:					zhoukeli(haxixi_keli)
 *					Filename:				isnwAllocator.h
 *					CreateTime:				2008/12/06
 *					ModifyTime:				2008/12/06
 *
 */

#ifndef __ISNW_ALLOCATOR_H__
#define __ISNW_ALLOCATOR_H__

#include "isnwTypes.h"
#include <memory>

namespace ISNW
{
namespace core
{
	template<typename T>
	class isnwAllocator
	{
	public:
		//! destructor
		virtual ~isnwAllocator(){}

		T* allocate(size_t cnt)
		{
			return (T*)(internal_new(cnt * sizeof(T)));
		}

		void deallocate(T* ptr)
		{
			internal_delete(ptr);
		}

		void construct(T* ptr, const T& e)
		{
			new ((void*)ptr) T(e);
		}

		void destruct(T* ptr)
		{
			ptr->~T();
		}

	protected:
		virtual void* internal_new(size_t size)
		{
			return operator new(size);
		}

		virtual void internal_delete(void* ptr)
		{
			if(ptr)	operator delete(ptr);
		}
	};
} // end namespace ISNW
} // end namespace core
#endif